package adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.animation.Animation;
import android.view.animation.AnimationUtils;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.parkcar.R;

import java.util.ArrayList;
import java.util.List;

import Modle.CarBean;

/**
 * Created by Administrator on 2016/3/17.
 */
public class CarAdapter extends BaseAdapter{
    private Context mContext;
    private List<CarBean> mDatas = new ArrayList<>();
    private boolean isDelete;
    private Animation mAnimation;
    public CarAdapter(Context mContext){
        this.mContext = mContext;
        mAnimation = AnimationUtils.loadAnimation(mContext, R.anim.enter_from_right);
    }
    @Override
    public int getCount() {
        return mDatas.size();
    }

    @Override
    public Object getItem(int i) {
        return mDatas.get(i);
    }

    @Override
    public long getItemId(int i) {
        return 0;
    }

    @Override
    public View getView(int i, View view, ViewGroup viewGroup) {
        ViewHolder mHolder;
        if(view==null){
            mHolder = new ViewHolder();
            view = LayoutInflater.from(mContext).inflate(R.layout.adapter_car,null);
            mHolder.car_name = (TextView) view.findViewById(R.id.car_name);
            mHolder.delete = (TextView) view.findViewById(R.id.delete);
            view.setTag(mHolder);
        }else{
            mHolder = (ViewHolder) view.getTag();
        }
        mHolder.car_name.setText(mDatas.get(i).getPlateNumber());
        if(isDelete&&mHolder.delete.getVisibility()!=View.VISIBLE){
            mHolder.delete.startAnimation(mAnimation);
            mHolder.delete.setVisibility(View.VISIBLE);
            mHolder.delete.setTag(i);
        }else{
            mHolder.delete.setVisibility(View.GONE);
        }
        return view;
    }
    class ViewHolder{
        TextView delete,car_name;
    }
    public void setDatas(List<CarBean> mDatas){
        this.mDatas = mDatas;
        notifyDataSetChanged();
    }
    public void setDelete(boolean delete){
        this.isDelete = delete;
        notifyDataSetChanged();
    }
    public void setDatas(List<CarBean> mDatas, boolean isDelete){
        this.mDatas = mDatas;
        this.isDelete = isDelete;
        notifyDataSetChanged();
    }
}
